package com.ysd.lis.controller.lab;

import com.ysd.common.Result;
import com.ysd.lis.annotation.MainInfoLog;
import com.ysd.lis.aspect.OperationType;
import com.ysd.lis.controller.pub.BaseController;
import com.ysd.lis.entity.lab.LabRepetition;
import com.ysd.lis.entity.lab.LabRepetitionDetail;
import com.ysd.lis.request.lab.LabRepetitionDto;
import com.ysd.lis.service.lab.LabRepetitionDetailService;
import com.ysd.lis.service.lab.LabRepetitionService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 复查记录
 *
 * @author wanghao
 * @create 2024/5/7 0007
 */
@RestController
@RequestMapping("/lab/repetition")
public class LabRepetitionController extends BaseController {

    @Autowired
    private LabRepetitionService labRepetitionService;

    @Autowired
    private LabRepetitionDetailService labRepetitionDetailService;

    @ApiOperation("新增复查记录")
    @PostMapping("/addRepetition")
//    @MainInfoLog(operationType = OperationType.INSERT, module = "检验报告", content = "新增复查记录", businessName = "rptResult")
    public Result addRepetition(@RequestBody LabRepetitionDto labRepetitionDto) {
        return labRepetitionService.addRepetition(labRepetitionDto);
    }

    @ApiOperation("获取复查记录列表")
    @GetMapping("/getRepetitionList/{mainInfoId}")
    public Result getRepetitionList(@PathVariable String mainInfoId) {
        return labRepetitionService.getRepetitionList(mainInfoId);
    }

    @ApiOperation("设置采信")
    @PostMapping("/setAccepted")
    public Result setAccepted(@RequestBody LabRepetition labRepetition) {
        labRepetition.setIsAccepted(1);
        boolean b = labRepetitionService.updateById(labRepetition);
        if (b) {
            return Result.succ(1, "设置采信成功", labRepetition);
        } else {
            return Result.fail("修改采信失败");
        }
    }

    @ApiOperation("修改复查原因")
    @PostMapping("/updateRepetition")
//    @MainInfoLog(operationType = OperationType.UPDATE, module = "检验报告", content = "修改复查原因", businessName = "rptResult")
    public Result updateRepetition(@RequestBody List<LabRepetition> labRepetition) {
        boolean b = labRepetitionService.saveOrUpdateBatch(labRepetition);
        if (b) {
            return Result.succ(1, "修改成功", null);
        } else {
            return Result.fail("修改失败");
        }
    }
    @ApiOperation("修改复查结果")
    @PostMapping("/updateRepetitionDetail")
    public Result updateRepetitionDetail(@RequestBody List<LabRepetitionDetail> labRepetitionDetail) {
        boolean b = labRepetitionDetailService.saveOrUpdateBatch(labRepetitionDetail);
        if (b) {
            return Result.succ(1, "修改成功", null);
        } else {
            return Result.fail("修改失败");
        }
    }
}

